Ext.namespace("NewCustomer");

NewCustomer.Feedback = function (p){
	this.parentWin=p
	
	this.hdSuperviseId = new Ext.form.Hidden({name:'superviseId'});
	this.txtSuperviseTitle = new Ext.form.TextField({
		fieldLabel: '问题标题',
		name:'superviseTitle',		
		maxLength:100,
		width: 540,
		disabled:true
	});
	
	this.txtManagerId=new Ext.form.Hidden({name:'managerId'});
	this.txtReportDept=new Ext.form.Hidden({name:'reportDept'});
	this.txtReportDeptName = new Ext.form.TextField({
		width: 120,
		fieldLabel: '责任部门',
		name:'reportDeptName',
		disabled:true
	});
	
	this.txtSuperviseContent = new Ext.form.TextArea({
		fieldLabel: '问题描述',
		name:'superviseContent',
		disabled:true,
		height:30,
		width: 540
	});
	
	this.typeStore  = new Ext.data.ArrayStore({
        	fields: ['value', 'name'],
        	data: OMS.ISSUE_TYPE2
    });
	this.txtIssueType = new Ext.form.ComboBox({
		width: 120,
		fieldLabel: '问题类别',
		name:'issueType',
		store: this.typeStore,
        valueField: 'value',
        displayField: 'name',
        disabled:true,
        mode: 'local'
	});
	//this.txtIssueType.on('select', this.changeType, this);	
	this.dtIssueDate = new Ext.form.DateField({
    	fieldLabel: '提问时间',
    	name:'issueDate',
		width: 120,
		disabled:true,
		format: 'Y-m-d'
	});
	this.typeLebel  = new Ext.data.ArrayStore({
        	fields: ['value', 'name'],
        	data: OMS.ISSUE_LEVEL2
    });
	this.txtInstancyLevel = new Ext.form.ComboBox({
		width: 120,
		fieldLabel: '紧急程度',
		name:'instancyLevel',
		store: this.typeLebel,
        valueField: 'value',
        displayField: 'name',
        disabled:true,
        mode: 'local'
	});
	
	this.hdInspector = new Ext.form.Hidden({name:'inspectorId'});
	this.txtInspectorName = new Ext.form.TextField({
        fieldLabel: '执行人',
        name:'inspectorName',
        width: 540,
        disabled:true
    });
	
	this.txtNotion = new Ext.form.TextArea({
		fieldLabel: '处理意见',
		name:'notion',
		width: 540,
		height: 30,
		disabled:true
	});
	this.txtCreateName = new Ext.form.TextField({
		fieldLabel: '填报人',
		name:'createName',
		width: 120,
		disabled:true
	});
	this.txtDeptName = new Ext.form.TextField({
		fieldLabel: '营业厅',
		name:'deptName',
		width: 120,
		disabled:true
	});
	
	this.txtFeedback = new Ext.form.TextArea({
		fieldLabel: '反馈情况',
		name:'feedback',
		width: 540,
		height: 50,
		maxLength:1000
	});
	this.btnSave = new Ext.Button({
    	text:'保存',
    	handler:this.onSave,
    	scope: this
    });
	this.form = new Ext.form.FormPanel({
		bodyStyle: 'padding: 5px 5px 0',
        frame:true,
        labelWidth: 70,
		labelAlign:'right',
		region:'north',	
		height: 240,	
		split:true,
		collapsible: true,
		items: [ this.txtSuperviseTitle,
        	this.txtSuperviseContent,{ layout: 'column', border: false, defaults: {layout: 'form', border: false},
	        	items: [ { columnWidth: .33, items: [this.txtIssueType]},
	        			{ columnWidth: .33, items: [this.txtReportDeptName]},
	        	         { columnWidth: .33, items: [this.dtIssueDate]}]
	    				},{ layout: 'column', border: false, defaults: {layout: 'form', border: false},
	        	items: [ { columnWidth: .33, items: [this.txtInstancyLevel]},
	        	         { columnWidth: .33, items: [this.txtCreateName]},
	        	         { columnWidth: .33, items: [this.txtDeptName]}]
	    	},this.txtNotion,this.txtInspectorName,
	    	this.txtManagerId,this.txtReportDept,
	    	this.hdInspector,this.hdSuperviseId,this.txtFeedback    	
	    	]
	});
	
	this.store = new Ext.data.JsonStore({
	    url: '../superviseIssue/listFeedback.form?timesnap=' + Date.parse(new Date()),
	    root: 'result',
	    totalProperty: 'total',
        remoteSort: true,
	    fields: ['taskExeId','taskExeUpdateDate','taskId','taskExeUserId','taskExePerformType',
	    'taskExeDispatcherId','taskExeStatus','taskExePercent','taskExeBackStatus',
	    'taskExeUserName']
	});
	//this.store.setDefaultSort('taskFeedbackId', 'desc');
	this.renderTaskStatus = function(value){
		return OMS.TASKSEXESTATUS[value];
	}
	this.renderState = function(value){
		return OMS.SUPERVISE_STATE[value];
	};
	this.columns =  [
	    {header: '执行表ID', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'taskExeId'},
	    {header: '负责人ID', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'taskExeUserId'},
	    {header: '执行人', sortable: true, align: 'center',width: 20,dataIndex: 'taskExeUserName'},
		{header: '更新日期', sortable: true, align: 'right',width: 20,dataIndex: 'taskExeUpdateDate'},
		{header: '对应ID', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'taskId'},		
		{header: '执行类型', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'taskExePerformType'},
		{header: '派送人', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'taskExeDispatcherId'},
		{header: '完成状态', sortable: true, align: 'right',width: 20,dataIndex: 'taskExeStatus',renderer:this.renderTaskStatus},
		{header: '完成百分比', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'taskExePercent'},
		{header: 'TASK_EXE_BACK_STATUS', sortable: true, align: 'right',hidden:true,width: 20,dataIndex: 'taskExeBackStatus'},
		{header: '意见内容', sortable: true, align: 'center',dataIndex: 'content'}
	];
	
	this.grid = new Ext.grid.EditorGridPanel({
		title:'任务反馈情况',
		region: 'center',
		cm: new Ext.grid.ColumnModel(this.columns),
		store:this.store,
		height: 140,
		autoScroll: true,
		clicksToEdit:1,
		viewConfig: { forceFit: true },
        collapsible:true
	});	
	NewCustomer.Feedback.superclass.constructor.call(this,{
		title: '厅问题督办反馈',
		width:700,
		height:420,
		resizable: false,
        modal: true,
        autoScroll: true,
		closeAction:'hide',
		items:[this.form, this.grid],
		buttonAlign:'center',
		buttons:[this.btnSave,{
            text: '关闭',
            scope: this,
            handler: function() {
	        	this.hide();
        	}
        }]
	});	
};

Ext.extend(NewCustomer.Feedback, Ext.Window, {
	initWin:function(data){
		this.form.getForm().setValues(data);
		this.grid.store.load({
			params:{superviseId:data.superviseId}
		});	
	},
	onSave: function() {
		if(!this.form.getForm().isValid()){
			Utils.info2("有必填项没有填写，请检查！",180);
			return;
		}
		var conn = new Ext.data.Connection({
  			url:'../superviseIssue/feedback.form?timesnap=' + Date.parse(new Date()),
  			method:'post'
  		})
  		var param={superviseId:this.hdSuperviseId.getValue(),
  					feedback:this.txtFeedback.getValue()};
  		//alert(Ext.util.JSON.encode(param));		
		Utils.request(conn,{
  			params:param,
  			scope:this,
  			success:function(data){
  				Utils.info2();
				this.scope.hide();
				this.scope.parentWin.queryIssue();
  			}
  		});
	}
});